<?php
namespace Home\Controller;
use Think\Controller;
class SweepController extends Controller {
	

    public function index(){
    	 $options=C('options');   
		 
    	$weObj = new \Org\Util\Wechat($options);
		
		$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $sign = $weObj->getJsSign($url);	
        $this->assign('arr',$sign);      
        $this->display();
    }
	 public function form(){
	 	$uid = I('uid');
		$type = I('type');
		$this->assign('type',$type);  
		$this->assign('uid',$uid);      
        $this->display();
    }
	 public function paly(){
	 	$feng=I('feng');
		$uid = I('uid');		
		$type = I('type');	
		$time=date("Y-m-d H:i:s",time());
		$re=M('score')->where("uid=".$uid)->find();
		if($type==3){		
		$data=array(
		"uid"=>$uid,	
		"g2_score"=>$feng,
		"g2_created"=>$time,
		"g2_status"=>1,
		);
		}
		if($type==4){
			if($feng<="35"){
				$jife=60;
			}
			if($feng>="36"&&$feng<="45"){
				$jife=70;
			}
			if($feng>="46"&&$feng<="50"){
				$jife=80;
			}
			if($feng>="51"&&$feng<="55"){
				$jife=90;
			}
			if($feng>="56"){
				$jife=100;
			}	
						
		$data=array(
		"uid"=>$uid,	
		"g3_score"=>$jife,
		"g3_created"=>$time,
		"g3_status"=>1,
		);
		}	
		if($re){		
			$res=M('score')->where("uid=".$uid)->data($data)->save();
		}else{
			$res=M('score')->data($data)->add();
		}
		if($res){
			$this->ajaxReturn(array('s'=>false,'m'=>"上传成功！"));
		}else{
			$this->ajaxReturn(array('s'=>true,'m'=>"上传失败！请重新扫码！"));
		}
    }
	 public function sign(){
	 	$uid = I('uid');
		$time=date("Y-m-d H:i:s",time());
		$res=M('user')->where('id="'.$uid.'"')->find();
		if($res['sign']==0){
			$data=array("sign"=>1,"signtime"=>$time);
		$re=M('user')->where('id="'.$uid.'"')->data($data)->save();
		
		if($re){
			$this->ajaxReturn(array('m'=>"签到成功！"));
		}else{
			$this->ajaxReturn(array('m'=>"签到失败！请重新扫码！"));
		}
       }else{
       		$this->ajaxReturn(array('m'=>"已签到！"));
       }	
    }
 	public function ewm(){
 		 $this->display();
 	}
}
